package by.airlanterns.web;

import by.airlanterns.service.ActionService;
import by.airlanterns.service.LanternService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Sergey
 * Date: 26.01.13
 * Time: 16:32
 * To change this template use File | Settings | File Templates.
 */

@Controller
@RequestMapping({"/index", "/"})
public class IndexController extends BaseController {

    @Autowired
    private LanternService lanternService;
    @Autowired
    private ActionService actionService;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView showIndex(HttpServletRequest request, HttpServletResponse response) {

        Map<String, Object> model = getModel();
        model.put("lanterns", lanternService.findByCategoryId(MAIN_CATEGORY_ID));
        model.put("small_lanterns", lanternService.findByCategoryId(SECOND_CATEGORY));
        model.put("last_action", actionService.getActiveAction());
        return new ModelAndView("index", model);
    }

}
